package com.osgc.rf.np.url.dao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.inca.np.gui.control.DBTableModel;
import com.inca.np.util.SelectHelper;
import com.osgc.rf.np.url.util.base.MenuItem;
public class User {

	private String username =null;
	private String userid =null;
	private String warehouseid =null;
	private String deptname=null;
	private String deptid=null;
	private String useContainer="0";
	private String tradecontainerflag="0";
	public String  getUseContainer() {
		return useContainer;
	}
	public void setUseContainer(String useContainer) {
		this.useContainer = useContainer;
	}
	public String getDeptname() {
		return deptname;
	}

	public void setDeptname(String deptname) {
		this.deptname = deptname;
	}

	public String getDeptid() {
		return deptid;
	}

	public void setDeptid(String deptid) {
		this.deptid = deptid;
	}

	private Date logintime =null;
	private Group group =null;
	private List<Group> groups =null;
	private MenuItem op =null;

	public User(String userid) throws Exception {
		this.userid = userid;
		groups = new ArrayList<Group>();
	}

	public String getWarehouseid() {
		return warehouseid;
	}

	public MenuItem getOp() {
		return op;
	}

	public void setOp(MenuItem op) {
		this.op = op;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public void setWarehid(String warehid) {
		this.warehouseid = warehid;
	}

	public void setLogintime(Date logintime) {
		this.logintime = logintime;
	}

	public String getUsername() {
		return username;
	}

	public String getUserid() {
		return userid;
	}

	public Date getLogintime() {
		return logintime;
	}

	public Group getGroup() {
		return group;
	}

	public void setGroup(Connection con,Group group) throws Exception {
		this.group = group;
		setGroupMenu(con);

	}
	/**
	 * @return the groups
	 */
	public List<Group> getGroups() {
		return groups;
	}
	
	public Group getGroup(String groupid) {
		for (Group g : groups) {
			if(g.getId().equals(groupid))
				return g;
		}
		return null;
	}
	
	public void setGroupMenu(Connection con) throws Exception {
		String groupid = group.getId();
		String sql = "select a.opid,a.opname,a.classname,c.warehouseid "
				+ " from np_op a, wms_task_group_op b,wms_task_group c where a.opid = b.opid and b.groupid=c.groupid "
				+ " and b.groupid=" + groupid;		
		DBTableModel userdb = new SelectHelper(sql).executeSelect(con, 0, 1000);
		group.getMenu().clear();
		for (int i = 0; i < userdb.getRowCount(); i++) {

			String opid = userdb.getItemValue(i, "opid");
			warehouseid = userdb.getItemValue(i, "warehouseid");
			String opname = userdb.getItemValue(i, "opname");
			String classname = userdb.getItemValue(i, "classname");
			MenuItem m = new MenuItem(opid, opname, "", classname,
					"");
			group.add(m);
		}
	}
	public void removeGroup() {
		group = null;
		
	}
	@Override
	public String toString() {
		return "id:"+userid+"  "+username;
	}
	public String getTradecontainerflag() {
		return tradecontainerflag;
	}
	public void setTradecontainerflag(String tradecontainerflag) {
		this.tradecontainerflag = tradecontainerflag;
	}
}
